import matplotlib.pyplot as plt
import numpy as np
from basic import *

ts1 = np.loadtxt('../data/pr_NY.csv')  # 降水量 # Y

def bins_plot(b):
	subsequence = ts1[:20]
	subsequence -= np.min(subsequence)
	subsequence /= np.max(subsequence)
	subsequence *= b
	subsequence += 1
	_max = max(subsequence)
	_min = min(subsequence)
	_range = (_max - _min)/b
	bins = np.arange(min(subsequence), max(subsequence)+0.1, _range)
	ans = np.digitize(subsequence, bins=bins)
	plt.hlines(y=bins, xmin=0, xmax=len(subsequence), color='gray', alpha=0.5)
	plt.plot(subsequence, label='original')
	plt.plot(ans, label='digitized')
	plt.xlabel('time')
	plt.ylabel('normalized data')
	

plt.figure(figsize=(12, 5))
plt.subplot(131)
bins_plot(4)
plt.title('4 bins')
plt.subplot(132)
bins_plot(5)
plt.title('5 bins')
plt.subplot(133)
bins_plot(6)
plt.title('6 bins')
plt.legend()
plt.tight_layout()
plt.savefig(PATH+'digitalized.pdf', format='pdf')
plt.show()